package org.example.design.singleton;

/**
 * @author huangshen
 * @version 0
 * @description 静态内部类单例
 * @since 2022/1/29 19:34
 */
public class StaticInnerSingleton {
    /**
     *  静态内部类单例
     *      优点： 采用类装载的机制保证初始化实例时只有一个线程
     *            静态内部类在 Singleton 类装载时不会立即实例化，而是在需要实例化时，调用getInstance方法才会装载 StaticInnerSingleton类
     *      缺点：
     */
    private StaticInnerSingleton() { }

    private static class StaticInnerSingletonInstance {
        private static final StaticInnerSingleton INSTANCE = new StaticInnerSingleton();
    }

    public static StaticInnerSingleton getInstance() {
        return StaticInnerSingletonInstance.INSTANCE;
    }
}
